package com.zmn.plat.services.impl.category;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.category.BaseCategoryAttributeEnum;
import com.zmn.plat.model.entity.category.BaseCategoryAttributeEnumQuery;
import com.zmn.plat.persistence.interfaces.category.AttributeEnumDAO;
import com.zmn.plat.services.interfaces.category.BaseCategoryAttributeEnumService;

/**
 * @author duanzuocai
 * @version v1.0
 * @since 2018/10/19 14:21
 */
@Service
public class BaseCategoryAttributeEnumServiceImpl implements BaseCategoryAttributeEnumService {
    @Resource
    AttributeEnumDAO attributeEnumDAO;

    @Override
    public BaseCategoryAttributeEnum findByKey(Integer id) {
        return attributeEnumDAO.findByKey(id);
    }

    @Override
    public List<BaseCategoryAttributeEnum> listPageByQuery(BaseCategoryAttributeEnumQuery query) {
        query.setTotalCount(attributeEnumDAO.countByQuery(query));
        return attributeEnumDAO.listPageByQuery(query);
    }

    @Override
    public List<BaseCategoryAttributeEnum> listByKeys(List<Integer> attrIds) {
        return attributeEnumDAO.listByKeys(attrIds);
    }

    @Override
    public List<BaseCategoryAttributeEnum> listAttributeId(Integer attributeId) {
        return attributeEnumDAO.listAttributeId(attributeId);
    }

    @Override
    public Integer countByQuery(BaseCategoryAttributeEnumQuery query) {
        return attributeEnumDAO.countByQuery(query);
    }

    @Override
    public void updateByKey(BaseCategoryAttributeEnum attributeEnum) {
        attributeEnumDAO.updateByKey(attributeEnum);
    }

    @Override
    public void updateSortKey(Integer enumId, Integer sort, String updater) {
        BaseCategoryAttributeEnum attributeEnum = new BaseCategoryAttributeEnum();

        attributeEnum.setEnumId(enumId);
        attributeEnum.setSort(sort);
        attributeEnum.setUpdater(updater);
        attributeEnum.setUpdateTime(DateUtil.getNow());

        attributeEnumDAO.updateSortKey(attributeEnum);
    }

    @Override
    public void updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);

        attributeEnumDAO.updateStatusBatch(dto);
    }

    @Override
    public Integer insert(BaseCategoryAttributeEnum attributeEnum) {
        return attributeEnumDAO.insert(attributeEnum);
    }

    @Override
    public Integer delete(int id) {
        return attributeEnumDAO.deleteByKey(id);
    }

    @Override
    public List<BaseCategoryAttributeEnum> listByCategoryId(Integer categoryId) {
        return attributeEnumDAO.listByCategoryId(categoryId);
    }
}
